package com.ynny.chapter05_06.dao;

import com.mysql.cj.CoreSession;
import com.ynny.chapter05_06.bean.Course;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Controller;

import java.util.List;
import java.util.Map;
@Controller("CourseMage")
public class CourseManageImpl  implements CourseMage{
    @Autowired
    JdbcTemplate jdbcTemplate;


    @Override
    public int updateCourse(Integer moiver, Integer AD, Integer PR) {
        String sql = "updata courses set"+moiver+"="+moiver+"-1"+AD+"="+AD+"-1"+PR+"="+PR+"-1";
        int num  = jdbcTemplate.update(sql);
        return  num ;
    }

    @Override
    public List<Course> selectAllCourse() {
        String sql = "select * from courses";
        List<Course> list = jdbcTemplate.query(sql,new BeanPropertyRowMapper<Course>(Course.class));
        return  list;
    }
}